var util = require('../../../utils/util.js');
Page({
  data: {

  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      express : 'express_' + options.express_id,
      express_id: options.express_id,
      express_name: options.express_name
    });
    wx.showLoading({
      title: '数据请求中',
    });
    if (util.get('express_' + options.express_id, 'outTime') == 'outTime') {
      that.searchExpress();
    } else {
      console.log('【物流信息】页面数据调用缓存。');
      wx.hideLoading();
      that.setData({
        express_info: wx.getStorageSync('express_'+that.data.express_id)
      })
    }
  },
  onPullDownRefresh: function () {

  },
  // 查询快递信息
  searchExpress() {
    var that = this;
    let times = 1800; // 缓存30分钟
    wx.cloud.callFunction({
      name: "getExpressInfo",
      data: {
        user_openid: wx.getStorageSync('openid'),
        express_id: that.data.express_id,
        express_name: that.data.express_name,
      },
      success: res => {
        wx.hideLoading();
        that.setData({
          express_info: JSON.parse(res.result).result
        });
        // 缓存times秒
        util.put('express_'+that.data.express_id, JSON.parse(res.result).result, times);
      }
    })
  }
})